package com.dinetech.dao;

import java.util.ArrayList;

import com.dinetech.ejecutor.R;
import com.dinetech.entidades.Ubicacion;
import com.dinetech.entidades.Session;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class UbicacionAdapter extends BaseAdapter {

	protected Activity activity;
	protected Fragment fragment;
	protected ArrayList<Ubicacion> items;
	Session s= Session.getInstance();
	
	public UbicacionAdapter(Activity activity, ArrayList<Ubicacion> Items){
		this.activity = activity;
		this.items = Items;	
	}
	
	public UbicacionAdapter(Fragment fragment, ArrayList<Ubicacion> Items){
		this.fragment = fragment;
		this.items = Items;	
	}
	
	@Override
	public int getCount() {
		
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return items.get(position).getIdUbicacion();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		
		if(convertView == null) {
        	LayoutInflater inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        	vi = inflater.inflate(R.layout.spinner_ubicacion_item, null);
        }
            
        Ubicacion item = items.get(position);                
        TextView nombreUbicacion = (TextView) vi.findViewById(R.id.txtNombreUbicacion);
        nombreUbicacion.setText(item.getNombreUbicacion());
        
        if(s.getNIVEL_EVENTO()==2){

	        if(item.getCodGenero()!= null ){
	        	TextView codSexo = (TextView) vi.findViewById(R.id.lblCodSexoSpinner);
		        TextView idReproductor = (TextView) vi.findViewById(R.id.lblIdReproductorSpinner);
		        codSexo.setText(item.getCodGenero().toString());
		        idReproductor.setText(String.valueOf(item.getIdReproductor()));
	        }
        }

        return vi;

	}

	
}
